package com.wcpdoc.exam.wang.vo;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.HashMap;

@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor

public class R {

    private Integer code;
    private String msg;
    private Object data;


    /**
     * 成功带数据
     *
     * @param data T data  分页数据结构：{total:100,list:[{id:1,name:"张三"},{id:2,name:"李四"}]}
     * @return R
     */
    public static R ok(Object data) {
        return R.builder().code(200).msg("请求成功").data(data).build();
    }

    /**
     * 成功不带数据
     *
     * @return R
     */
    public static R ok() {
        return R.builder().code(200).msg("请求成功").data(null).build();
    }

    /**
     * 失败：不带信息
     *
     * @return R
     */
    public static R error() {
        return R.builder().code(500).msg("请求失败").data(null).build();
    }

    /**
     * 失败：带信息
     *
     * @return R
     */
    public static R error(String msg) {
        return R.builder().code(500).msg(msg).data(null).build();
    }


    /**
     * 分页
     */
    public static R page(long total, Object list) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("list", list);
        map.put("total", total);
        return R.builder().code(200).msg("请求成功").data(map).build();
    }
}
